package com.oracle.oa.dao.impl;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.oracle.oa.dao.PreContractDao;

public class PreContractDaoImpl extends BaseDaoImpl implements PreContractDao {

	
	public int deleteByProperty(Class clzz, String name, Object value) {
		// or String hqlDelete = "delete Customer where name = :oldName";
			//this.openSession();
		  Session session = this.getHibernateTemplate().getSessionFactory()
				.openSession();
			Transaction tx = null;
			int deletedEntities = 0;
		    try {
				tx=session.beginTransaction();
				String hqlDelete = "delete from "+clzz.getSimpleName()+" where " +name+ " = " + value;
				deletedEntities= session.createQuery( hqlDelete).executeUpdate();
				tx.commit();
			} catch (HibernateException e) {
				tx.rollback();
				e.printStackTrace();
			}finally{
			      session.close();
			}
			return deletedEntities;
		}
}
